{extend name="public:public" /}
{block name="section"}
<section class="Hui-article-box">
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 首页
        <span class="c-gray en">&gt;</span> 用户管理
        <span class="c-gray en">&gt;</span> 会员等级
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l">
					<a href="javascript:;" onclick="member_add('添加','add','','510')" class="btn btn-primary radius">
						<i class="Hui-iconfont">&#xe600;</i> 添加等级</a>
				</span>
                <span class="r">共有数据：<strong>{:count(123)}</strong> 条</span> </div>
            <div class="mt-20">
                <table class="table table-border table-bordered table-hover table-bg table-sort">
                    <thead>
                    <tr class="text-c">
                        <th width="80">ID</th>
                        <th width="100">等级名称</th>
                        <th width="100">消费额度_低</th>
                        <th width="100">消费额度_高</th>
                        <th>优享折扣</th>
                        <!--<th width="100">状态</th>-->
                        <th width="100">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {volist name="data" id="vo"}
                    <tr class="text-c">
                        <td>{$vo.id}</td>

                        <td>{$vo.level_name}</td>
                        <td ondblclick="change_title(this)">{$vo.pay_require_min}</td>
                        <td ondblclick="change_title(this)">{$vo.pay_require_max}</td>
                        <td>{$vo.rate}</td>
                        <td class="td-manage">
                            <a title="编辑" href="javascript:;" onclick="member_edit('编辑','edi','{$vo.id}','','510')" class="ml-5" style="text-decoration:none">
                                <i class="Hui-iconfont">&#xe6df;</i>
                            </a>
                            <a title="删除" href="javascript:;" onclick="member_del(this,'{$vo.id}')" class="ml-5" style="text-decoration:none">
                                <i class="Hui-iconfont">&#xe6e2;</i>
                            </a>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>
        </article>
    </div>
</section>
<script type="text/javascript">

    $('#menu-user').children('dt').addClass('selected');
    $('#menu-user').children('dd').show();
    $('#menu-user').children('dd').find('a').eq(1).css({
        color:'#148cf1',
        backgroundColor:'#FFF'
    });
    function change_title(obj){
        var val = $(obj).html();
        $(obj).html("<input type='text' onblur='change_tit(this)' class='input-text' value='"+val+"' name='title' />");
        $(obj).find('input').focus();
    }

    function change_tit(obj){
        var title = $(obj).val();
        var id = $(obj).parent().siblings(":first").html();
        $.ajax({
            type: 'POST',
            url: 'change_title',
            data:{'id':id,'title':title},
            dataType: 'json',
            success: function(data){
                layer.msg(data.msg,{icon:data.icon,time:1000},function () {
                    if(data.status == 1){
                        $(obj).parent().html(title);
                    }
                });

            },
            error:function(data) {
                layer.msg('服务器错误',{icon:2,time:1000});
            },
        });

    }

    $(function(){

    });

    /*用户-停用*/
    function member_stop(obj,id){
        layer.confirm('确认要停用吗？',function(index){
            $.ajax({
                type: 'POST',
                url: 'change',
                data:{'id':id},
                dataType: 'json',
                success: function(data){
                    layer.msg(data.msg,{icon:data.icon,time:1000},function () {
                        if(data.status == 1){
                            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_start(this,'+id+')" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe6e1;</i></a>');
                            $(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已停用</span>');
                            $(obj).remove();
                        }
                    });

                },
                error:function(data) {
                    layer.msg('服务器错误',{icon:2,time:1000});
                },
            });


        });
    }

    /*用户-启用*/
    function member_start(obj,id){
        layer.confirm('确认要启用吗？',function(index){
            $.ajax({
                type: 'POST',
                url: 'change',
                data:{'id':id},
                dataType: 'json',
                success: function(data){
                    layer.msg(data.msg,{icon:data.icon,time:1000},function () {
                        if(data.status == 1){
                            $(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="member_stop(this,'+id+')" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a>');
                            $(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
                            $(obj).remove();
                        }
                    });

                },
                error:function(data) {
                    layer.msg('服务器错误',{icon:2,time:1000});
                },
            });

        });
    }
    function member_add(title,url,w,h){
        layer_show(title,url,w,h);
    }
    /*用户-编辑*/
    function member_edit(title,url,id,w,h){
        layer_show(title,url+'/id/'+id,w,h);
    }
    function member_del(obj,id){
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                type: 'POST',
                url: 'del',
                data:{'id':id},
                dataType: 'json',
                success: function(data){
                    layer.msg(data.msg,{icon:data.icon,time:1000},function () {
                        if(data.status == 1){
                            $(obj).parents("tr").remove();
                        }
                    });

                },
                error:function(data) {
                    layer.msg('服务器错误',{icon:2,time:1000});
                },
            });
        });
    }
</script>
{/block}

